gpointer data)
{
struct {
- int width;
- int height;
+ gint width;
+ gint height;
+ gboolean preserve_aspect_ratio;
} *info = data;
g_return_if_fail (width > 0 && height > 0);
- if ((double)height * (double)info->width >
- (double)width * (double)info->height) {
- width = 0.5 + (double)width * (double)info->height / (double)height;
- height = info->height;
+ if(info->preserve_aspect_ratio) {
+ if ((double)height * (double)info->width >
+ (double)width * (double)info->height) {
+ width = 0.5 + (double)width * (double)info->height / (double)height;
+ height = info->height;
+ } else {
+ height = 0.5 + (double)height * (double)info->width / (double)width;
+ width = info->width;
+ }
} else {
- height = 0.5 + (double)height * (double)info->width / (double)width;
width = info->width;
+ height = info->height;
}
-
+
gdk_pixbuf_loader_set_size (loader, width, height);
}
/**
- * gdk_pixbuf_new_from_file_at_size:
+ * gdk_pixbuf_new_from_file_at_scale:
* @filename: Name of file to load.
* @width: The width the image should have
* @height: The height the image should have
+ * @preserve_aspect_ratio: %TRUE to preserve the image's aspect ratio
* @error: Return location for an error
*
* Creates a new pixbuf by loading an image from a file. The file format is
* detected automatically. If %NULL is returned, then @error will be set.
* Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
- * The image will be scaled to fit in the requested size, preserving its aspect ratio.
+ * The image will be scaled to fit in the requested size, optionally preserving
+ * the image's aspect ratio.
*
- * Return value: A newly-created pixbuf with a reference count of 1, or %NULL if
- * any of several error conditions occurred: the file could not be opened,
+ * Return value: A newly-created pixbuf with a reference count of 1, or %NULL
+ * if any of several error conditions occurred: the file could not be opened,
* there was no loader for the file's format, there was not enough memory to
* allocate the image buffer, or the image file contained invalid data.
*
- * Since: 2.4
+ * Since: 2.6
**/
GdkPixbuf *
-gdk_pixbuf_new_from_file_at_size (const char *filename,
- int width,
- int height,
- GError **error)
+gdk_pixbuf_new_from_file_at_scale (const char *filename,
+ int width,
+ int height,
+ gboolean preserve_aspect_ratio,
+ GError **error)
{
+
GdkPixbufLoader *loader;
GdkPixbuf *pixbuf;
struct {
gint width;
gint height;
+ gboolean preserve_aspect_ratio;
} info;
g_return_val_if_fail (filename != NULL, NULL);
info.width = width;
info.height = height;
+ info.preserve_aspect_ratio = preserve_aspect_ratio;
g_signal_connect (loader, "size-prepared", G_CALLBACK (size_prepared_cb), &info);
return pixbuf;
}
+/**
+ * gdk_pixbuf_new_from_file_at_size:
+ * @filename: Name of file to load.
+ * @width: The width the image should have
+ * @height: The height the image should have
+ * @error: Return location for an error
+ *
+ * Creates a new pixbuf by loading an image from a file. The file format is
+ * detected automatically. If %NULL is returned, then @error will be set.
+ * Possible errors are in the #GDK_PIXBUF_ERROR and #G_FILE_ERROR domains.
+ * The image will be scaled to fit in the requested size, preserving
+ * the image's aspect ratio.
+ *
+ * Return value: A newly-created pixbuf with a reference count of 1, or
+ * %NULL if any of several error conditions occurred: the file could not
+ * be opened, there was no loader for the file's format, there was not
+ * enough memory to allocate the image buffer, or the image file contained
+ * invalid data.
+ *
+ * Since: 2.4
+ **/
+GdkPixbuf *
+gdk_pixbuf_new_from_file_at_size (const char *filename,
+ int width,
+ int height,
+ GError **error)
+{
+ return gdk_pixbuf_new_from_file_at_scale (filename,
+ width, height,
+ TRUE, error);
+}
+
static void
info_cb (GdkPixbufLoader *loader,
int width,